package com.maxmlr.music.song.controller;

import com.maxmlr.music.song.entity.Song;
import com.maxmlr.music.song.service.SongService;
import io.swagger.annotations.Api;
import lombok.extern.slf4j.Slf4j;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

import java.io.Serializable;

/**
 * @author max
 * @version 1.0
 * @ClassName AdminSongController
 * @Description 歌曲信息表 页面跳转控制器
 * @Copyright Copyright (c) 2020: www.maxmlr.com.
 * @since 2020-06-18
 */
@Slf4j
@Controller
@Api(value = "/song/song", tags = "Song 页面跳转控制器")
@RequestMapping("/song/song")
public class AdmSongController {

    @Autowired
    public SongService service;

    /**
     *  功能列表主页
     *
     * @return string
     */
    @GetMapping
    @RequiresPermissions("song:song:song")
    public String song() {
        return "song/song/song";
    }

    /**
     *  添加页面
     *
     * @return string
     */
    @GetMapping("/add")
    @RequiresPermissions("song:song:add")
    public String add(Integer singerId, Integer specialId, Model model) {
        model.addAttribute("singerId", singerId);
        model.addAttribute("specialId", specialId);
        return "song/song/add";
    }

    /**
     *  编辑页面
     *
     * @return string
     */
    @GetMapping("/edit/{id}")
    @RequiresPermissions("song:song:edit")
    public String edit(@PathVariable("id") Serializable id , Model model) {
        Song song = service.getById(id);
        model.addAttribute("song", song);
        return "song/song/edit";
    }


}
